package io.kimmking.statemachine02.squirrel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.squirrelframework.foundation.fsm.StateMachineBuilderFactory;
import org.squirrelframework.foundation.fsm.UntypedStateMachine;
import org.squirrelframework.foundation.fsm.UntypedStateMachineBuilder;

@Configuration
public class OrderConfiguration {

    @Autowired
    OrderService orderService;

    @Bean
    public SubmitOrderStateMachine createFSM() {
        UntypedStateMachineBuilder builder = StateMachineBuilderFactory.create(SubmitOrderStateMachine.class);
        SubmitOrderStateMachine fsm = builder.newAnyStateMachine(OrderState.INIT);
        fsm.setOrderService(orderService);
        return fsm;
    }

}
